package writenote.io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Buffered {
    public static void main(String[] args) throws IOException {
        /*缓冲流（高级流）内部有一个字节数组，默认长度8k用来提高读写效率，若数组的数据未写满，则不会真是写出
         * BufferedOutputStream
         * BufferedInputStream
         * 继承自OutputStream*/
        //缓冲字节流复制文件
        /*FileInputStream fis = new FileInputStream("mn.png");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos  = new FileOutputStream("mn_cp.png");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        int d;
        long start = System.currentTimeMillis();
        while ((d=bis.read())!=-1){
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕，耗时："+(end-start)+"ms");
        bis.close();//关闭时关闭高级流即可
        bos.close();*/
        //缓冲字节流写出文件：
        /*FileOutputStream fos = new FileOutputStream("fos.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        String line = "加油！奥利给！";
        byte[] data =line.getBytes(StandardCharsets.UTF_8);
        bos.write(data);
        line ="这就上高速了吗";
        data =line.getBytes(StandardCharsets.UTF_8);
        bos.write(data);
        bos.flush();//强制将缓冲区中已经缓存的数据一次性写出
        bos.close();*/
    }
}
